<include file="../Public/_header" />
<div class="so_main">
  <div class="page_tit">标签管理</div>
  <div class="Toolbar_inbox">
    <div class="page right">{$page}</div>
    <a href="javascript:void(0);" class="btn_a" onclick="addTag();"><span>添加标签</span></a>
     <a href="javascript:void(0);" class="btn_a" onclick="recmentTag(1);"><span>推荐标签</span></a>
     <a href="javascript:void(0);" class="btn_a" onclick="recmentTag(0);"><span>取消推荐</span></a>
    <a href="javascript:void(0);" class="btn_a" onclick="del();"><span>删除标签</span></a>
  </div>
  
  <div class="list">
  <table  width="100%" border="0" cellspacing="0" cellpadding="0">
  <tbody>
  <tr>
    <th style="width:30px;">
        <input type="checkbox" id="checkbox_handle" onclick="checkAll(this)" value="0">
        <label for="checkbox"></label>
    </th>
    <th class="line_l">ID</th>
    <th class="line_l">标签名称</th>
    <th class="line_l">推荐</th>
    <th class="line_l">操作</th>
  </tr>
  </tbody>
  <tbody id="tag_list">
  <volist id="vo" name="taglist">
      <tr overstyle='on' id="tag_{$vo.tag_id}">
        <td><input type="checkbox" name="checkbox" id="checkbox2" onclick="checkon(this)" value="{$vo.tag_id}"></td>
        <td>{$vo.tag_id}</td>
        <td id="tag_name{$vo['tag_id']}">{$vo.tag_name}</td>
        <td id="recommend_{$vo['tag_id']}"><php>if($vo['recommend'] == 1){</php> 是 <php>}else{</php> 否 <php>}</php></td>
        <td><if condition="$vo['recommend'] == 1">
            <a href="javascript:void(0);" onclick="recmentTag(0,{$vo['tag_id']});">取消推荐</a>
            <else/>
            <a href="javascript:void(0);" onclick="recmentTag(1,{$vo['tag_id']});">推荐</a>
            </if>&nbsp;&nbsp;&nbsp;&nbsp;
            <a href="javascript:void(0);" onclick="editTag({$vo['tag_id']});">编辑</a> &nbsp;&nbsp;&nbsp;&nbsp;
            <a href="javascript:void(0);" onclick="del({$vo['tag_id']});">删除</a>  
        </td>
      </tr>
  </volist> 
  </tbody>
  </table>

  </div>
  <div class="Toolbar_inbox">
  <div class="page right">{$page}</div>
    <a href="javascript:void(0);" class="btn_a" onclick="add();"><span>添加标签</span></a>
    <a href="javascript:void(0);" class="btn_a" onclick="recmentTag(1)"><span>推荐标签</span></a>
     <a href="javascript:void(0);" class="btn_a" onclick="recmentTag(0);"><span>取消推荐</span></a>
    <a href="javascript:void(0);" class="btn_a" onclick="del();"><span>删除标签</span></a>
  </div>
</div>

<script>
    //鼠标移动表格效果
    $(document).ready(function(){
        $("tr[overstyle='on']").hover(
          function () {
            $(this).addClass("bg_hover");
          },
          function () {
            $(this).removeClass("bg_hover");
          }
        );
    });
    
    function checkon(o){
        if( o.checked == true ){
            $(o).parents('tr').addClass('bg_on') ;
        }else{
            $(o).parents('tr').removeClass('bg_on') ;
        }
    }
    
    function checkAll(o){
        if( o.checked == true ){
            $('input[name="checkbox"]').attr('checked','true');
            $('tr[overstyle="on"]').addClass("bg_on");
        }else{
            $('input[name="checkbox"]').removeAttr('checked');
            $('tr[overstyle="on"]').removeClass("bg_on");
        }
    }

    //获取已选择标签的ID数组
    function getChecked() {
        var gids = new Array();
        $.each($('input:checked'), function(i, n){
            gids.push( $(n).val() );
        });
        return gids;
    }

    //添加标签
    function addTag() {
        ui.box.load("{:U('admin/Blog/addTag')}", {title:'添加标签'});
    }
    
    //编辑标签
    function editTag(tag_id) {
        ui.box.load("{:U('admin/Blog/editTag')}&tag_id="+tag_id, {title:'编辑标签'});
    }
    //推荐标签
	function recmentTag(type,tag_id){
		var  vv = type? '是':'否';
	    tag_id = tag_id ? tag_id : getChecked();
        tag_id = tag_id.toString();
        if(tag_id == '') return false;

        //提交推荐
        $.post("{:U('admin/Blog/doRecommendTag')}", {tag_id:tag_id, type:type}, function(res){
	        if(res == '1') {
		        tag_id = tag_id.split(',');
		        $.each(tag_id, function(i,n){
		            $('#recommend_'+n).text(vv);
		        });
	            ui.success('操作成功');
	        }else {
	        	ui.success('操作失败');
	        }
        });	
		
	}
    //删除标签
    function del(tag_id) {
        tag_id = tag_id ? tag_id : getChecked();
        tag_id = tag_id.toString();
        if(tag_id == '' || !confirm('删除成功后将无法恢复，确认继续？')) return false;

        //提交删除
        $.post("{:U('admin/Blog/dodelTag')}", {tag_id:tag_id}, function(res){
	        if(res == '1') {
		        tag_id = tag_id.split(',');
		        $.each(tag_id, function(i,n){
		            $('#tag_'+n).remove();
		        });
	            ui.success('删除成功');
	        }else {
	        	ui.success('删除失败');
	        }
        });
        
        
    }
</script>

<include file="../Public/_footer" />